// Author	: damphat@gmail.com
// Created	: 01/12/2008

#pragma once
#include "vn/IOCommon.h"

IO_BEGIN

class Directory {
public:
	static String 
	GetCurrent() {
		TCHAR buf[MAX_PATH];
		DWORD dwret = GetCurrentDirectory(MAX_PATH, buf);
		CHECK_IO(dwret != 0);	
		return buf;
	}

	static void
	SetCurrent(String path) {
		BOOL bret = SetCurrentDirectory(path.C_STR());
		CHECK_IO(bret);
	}

	static void
	Create(String path) {
		BOOL bret = CreateDirectory(path.C_STR(), NULL);
		CHECK_IO(bret);
	}

	static bool
	Remove(String path) {
		BOOL bret = RemoveDirectory(path.C_STR());
		if(!bret) {
			if(GetLastError() == ERROR_FILE_NOT_FOUND) {
				return false;
			}
			CHECK_IO(false);
		}
		return true;
	}

	static void
	Move(String srcPath, String desPath) {
		BOOL bret = MoveFile(srcPath.C_STR(), desPath.C_STR());
		CHECK_IO(bret);
	}

	static FileAttributes
	GetAttributes(String path) {
		DWORD dwAttrs = GetFileAttributes(path.C_STR());
		CHECK_IO(dwAttrs != INVALID_FILE_ATTRIBUTES);
		return dwAttrs;
	}

	static void
	SetAttributes(String path, FileAttributes attributes) {
		BOOL bret = SetFileAttributes(path.C_STR(), attributes);
		CHECK_IO(bret);
	}

	static bool
	Exists(String path) {
		DWORD dwAttrs = GetFileAttributes(path.C_STR());
		return dwAttrs != INVALID_FILE_ATTRIBUTES;
	}

};

IO_END
